package com.alibaba.shopping_manager_api.controller;

import com.alibaba.shopping_common.pojo.SeckillGoods;
import com.alibaba.shopping_common.result.BaseResult;
import com.alibaba.shopping_common.service.SeckillGoodsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName seckillGoodsController
 * @Description TODO
 * @Author Leo
 * @Date 2024/12/10 20:46
 */
@RestController
@RequestMapping("/seckillGoods")
public class seckillGoodsController {

    @DubboReference
    private SeckillGoodsService seckillGoodsService;

    /**
     * 新增秒杀商品
     * @param seckillGoods
     * @return
     */
    @PostMapping("/add")
    public BaseResult<SeckillGoods> add(@RequestBody SeckillGoods seckillGoods){
        seckillGoodsService.add(seckillGoods);
        return BaseResult.OK(seckillGoods);
    }

    /**
     * 更新秒杀商品
     * @param seckillGoods
     * @return
     */
    @PutMapping("/update")
    public BaseResult<SeckillGoods>update(@RequestBody SeckillGoods seckillGoods){
        seckillGoodsService.update(seckillGoods);
        return BaseResult.OK(seckillGoods);
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/findPage")
    public BaseResult<Page<SeckillGoods>>findPage(int page,int size){
        Page<SeckillGoods> page1 = seckillGoodsService.findPage(page, size);
        return BaseResult.OK(page1);
    }
}




